<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Setoran extends CI_Controller {

	public function __construct() {
		parent::__construct();
		$this->load->library('form_validation');
	}

	public function index(){
		$this->load->model('setor','',true);
		$data['setor'] = $this->setor->get_all();
		$this->load->view('header');
		$this->load->view('menu');
		$this->load->view('setoran',$data);
		$this->load->view('footer');
	}

	public function insert(){
		$datainput = array(
				'nomer_bukti' 			=> $this->input->post('nomer_bukti'),
				'tanggal' 					=> $this->input->post('tanggal'),
				'keterangan' 			=> $this->input->post('keterangan'),
				'karyawan'			=> $this->input->post('karyawan'),
				'nominal'			=> $this->input->post('nominal')
			);
		$this->load->model('setor','',true);
		$this->form_validation->set_rules('nama', 'nama', 'trim|required|is_unique[setoran.nama]');
		if ($this->form_validation->run() == FALSE) {
			$menu['error'] = true;
			$this->load->model('setor','',true);
			$data['setor'] = $this->setor->get_all();
			$this->load->view('header');
			$this->load->view('menu');
			$this->load->view('setoran',$data);
			$this->load->view('footer');
		} else {
			$this->setor->insert($datainput );
			redirect('bar');
		}	
		
		$this->setor->insert($datainput);
			redirect('setoran');
	}

	public function delete($data){
		$this->load->model('setor','',true);
		$this->setor->delete($data);
		redirect('bar');
	}

	public function edit($id){
		$this->load->model('setor','',true);
		$data['detail'] = $this->setor->get_by_id($id);
		
		
		$data['setor'] = $this->setor->get_all();
		$this->load->view('header');
		$this->load->view('menu');
		$this->load->view('setoran',$data);
		$this->load->view('footer');
	}

	public function update(){
		
		$data = array(
				'nomer_bukti' 			=> $this->input->post('nomer_bukti'),
				'tanggal' 					=> $this->input->post('tanggal'),
				'keterangan' 			=> $this->input->post('keterangan'),
				'kar'			=> $this->input->post('karyawan'),
			);
			
		$id = $this->input->post('id_setoran');
		$this->load->model('setor','',true);
		$this->form_validation->set_rules('nama', 'nama', 'trim|required|is_unique[setoran.nama]');
		if ($this->form_validation->run() == FALSE) {
			$menu['error'] = true;
			$this->load->model('setor','',true);
			$data['setor'] = $this->setor->get_all();
			$this->load->view('header');
			$this->load->view('menu');
			$this->load->view('setoran',$data);
			$this->load->view('footer');
		} else {
			$this->setor->update($id,$data);
			redirect('setoran');
		}
		
	}
}
